home *** CD-ROM | disk | FTP | other *** search
- /*
- * event.c - the main event loop
- */
-
- #include <quickdraw.h>
- #include <memory.h>
- #include <window.h>
- #include <dialog.h>
- #include <menu.h>
- #include <event.h>
- #include <desk.h>
- #include <control.h>
- #include <packages.h>
- #include <toolutil.h>
- #include <syserr.h>
-
- #include "critic.h"
-
- /*
- * doevent() - one loop through the main event handler
- * Returns 1 if the user wants to continue; 0 if it's time to quit
- */
-
- int
- doevent()
- {
- GrafPtr saveport;
- EventRecord myevent;
- char whichchar; /* the char that was typed */
- WindowPtr whichwindow; /* Points to window of MouseDown */
- WindowPtr activewindow; /* Points to the frontmost window */
- DialogPtr whichdialog; /* dialog of MouseDown */
- short whichitem; /* mouse's dialog item */
- long menucommand; /* a menu command to do (menu + item) */
- int windowcode; /* What mouse was in when event posted. */
- ControlHandle whichcontrol; /* the control that was pressed */
- short partcode; /* the pressed part of that control */
- Point pt; /* temp point */
- int userdone; /* True when user wants to exit program */
- Point dlgorig; /* topLeft of movable dialogs */
-
- userdone = 0;
- SystemTask(); /* give the system a moment of time */
-
- /*
- * see which window is currently selected
- * (for non-mouse events),
- * Then grab an event and interpret it.
- */
-
- GetPort(&activewindow);
-
- if (!GetNextEvent(everyEvent, &myevent)) {
- draw_idle();
- } else if ((myevent.modifiers & cmdKey) &&
- (myevent.what == keyDown || myevent.what == autoKey)) {
-
- /*
- * It's a command-key keystroke.
- * (command keystrokes are handled here since dialogs can't)
- */
-
- whichchar = (char) (myevent.message & charCodeMask);
- markmenus(activewindow);
- menucommand = MenuKey(whichchar);
- userdone = docommand(menucommand);
- } else if (IsDialogEvent(&myevent)) {
- /* here's where we'd handle modeless dialog events */
- } else {
- switch (myevent.what) {
- case keyDown:
- case autoKey:
- criticize();
- break;
- case updateEvt: /* update the appropriate window */
- if ((WindowPtr)(myevent.message) == windoc) {
- redoc();
- }
- break;
- case activateEvt: /* activate or deactivate window */
- if (myevent.modifiers & 1) {
- SetPort((WindowPtr) myevent.message);
- } else {
- SetPort(screenport);
- }
- break;
- case diskEvt: /* disk inserted - eject or init it */
- if (HiWord(myevent.message) != noErr) {
- dlgorig.h = 90; dlgorig.v = 100;
- (void) DIBadMount(pass(dlgorig), myevent.message);
- }
- break;
- case mouseDown: /* a mouse click someplace */
-
- windowcode = FindWindow(pass(myevent.where), &whichwindow);
- switch (windowcode) {
- case inSysWindow: /* a DA's window */
- SystemClick(&myevent, whichwindow);
- break;
- case inMenuBar: /* a menu item */
- markmenus(activewindow);
- menucommand = MenuSelect(pass(myevent.where));
- userdone = docommand(menucommand);
- break;
- case inGoAway: /* Close box */
- if (TrackGoAway(whichwindow, pass(myevent.where))) {
- if (whichwindow == windoc) {
- userdone = 1;
- }
- }
- break;
- case inZoomIn:
- case inZoomOut: /* Zoom box */
- case inGrow: /* Grow Region */
- case inDrag: /* Title Bar */
- case inContent: /* Somewhere in the window */
- if (whichwindow != FrontWindow()) {
- /* the window isn't active - just activate it */
- SelectWindow(whichwindow);
- } else {
-
- /*
- * The window is active,
- * interpret the mouse-down in this window's context.
- */
-
- GlobalToLocal(&myevent.where);
- if (whichwindow == windoc) { /* it's our window */
- criticize();
- }
- }
- break;
- }
- break;
- }
- }
- return(!userdone);
- }
-